package com.fcscs.cservice.client.main.configuration.iguest;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.IconButtonEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.fcscs.core.common.authority.CServiceAuthority;
import com.fcscs.core.common.authority.UserAuthority;
import com.fcscs.core.domain.IdNameModel;
import com.fcscs.core.domain.Property;
import com.fcscs.core.gwt.common.AsyncCallbackListener;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.SessionContext;
import com.fcscs.core.gwt.common.ui.CenteredInfo;
import com.fcscs.core.gwt.common.ui.FcsFields.EasyClearCombobox;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.core.gwt.common.ui.FcsFields.HighLightIconButton;
import com.fcscs.core.gwt.common.ui.FcsPanel;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.common.MultiLanguageConstants;
import com.fcscs.cservice.client.common.UIUtils;
import com.fcscs.cservice.client.common.controller.CServiceCommonServiceController;
import com.fcscs.cservice.client.common.model.configuration.checkin.MessageItemsExpressGWTEnum;
import com.fcscs.cservice.client.common.model.configuration.checkin.MessageItemsExpressGWTEnumModelData;
import com.fcscs.cservice.client.common.model.configuration.reservation.PropertyIdNameModelData;
import com.fcscs.cservice.domain.ConstantsLanguageValue;
import com.fcscs.cservice.domain.ConstantsLanguageValueId;
import com.fcscs.cservice.domain.ExpressCheckInConfig;
import com.fcscs.share.gwt.common.ShareGWTConstants;
import com.fcscs.share.gwt.common.ui.MultiLanguageDialog;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class iGuestHotelReservationPanel extends FcsPanel {
	private VerticalPanel vp;
	private FieldSet fieldset1;
	private Radio emailRadio;
	private Radio printerRadio;
	private TextField<String> emailAddressField;
	private TextField<String> serverNameField;
	private TextField<String> fromExpressCheckin;
	private TextField<String> subjectCheckin;
	private TextField<String> subjectCheckinTimeout;
	private EasyClearCombobox<MessageItemsExpressGWTEnumModelData> titleMessageItemsCombox;
	private ListStore<MessageItemsExpressGWTEnumModelData> titleMessageItemsListStore;
	private TextField<String> checkinrequestsubmitted;
	private TextField<String> alreadycheckin;
	private TextArea textAreaexpresscheckin;
	private TextField<String> timeOutField;
	private Radio emailRadioAlert;
	private Radio printerRadioAlert;
	private TextField<String> emailAddressFieldAlert;
	private TextField<String> serverNameFieldAlert;
	private ExpressCheckInConfig currentExpressCheckInConf;
	private boolean isFocus = true;
	private EasyClearCombobox<PropertyIdNameModelData> propCombox;
	private ListStore<PropertyIdNameModelData> propListStore;
	private List<IdNameModel<Property>> propGroupIdNames;
	private MultiLanguageDialog fromDialog;
	private MultiLanguageDialog subjectCheckinRequestDialog;
	private MultiLanguageDialog subjectCheckinRequestTimeoutDialog;
	private MultiLanguageDialog checkinRequestSubmittedDialog;
	private MultiLanguageDialog alreadyCheckinDialog;
	private Map<String, String> fromExpresscheckinMap;
	private Map<String, String> subjectCheckinRequestMap;
	private Map<String, String> subjectCheckinRequestTimeoutMap;
	private Map<String, String> checkinRequestSubmittedMap;
	private Map<String, String> alreadyCheckinMap;
	
	private FormButton saveButton;
	private FieldSet fieldsetRequestSubmitted;
	private TextArea textareaRequestSubmitted;
	private FieldSet fieldsetFromhotelReser;
	private TextField<String> fromHotelReserField;
	private TextField<String> subjectReserSubmitField;
	private FieldSet fieldsetReserSubmit;
	private FieldSet fieldsetRequestSubmitMesTem;
	private FieldSet fieldsetRequestSubmitAckMesTem;
	
	public iGuestHotelReservationPanel(String id) {
		super(id);
	}

	public HighLightIconButton MultiEditBtn(){
		HighLightIconButton iconBtn = new HighLightIconButton(
				ShareGWTConstants.CSS_EDIT_SM_ICON, new SelectionListener<IconButtonEvent>() {
					public void componentSelected(IconButtonEvent ie){
						//dialog show method
					}
				});
		iconBtn.setTitle(CoreConstants.CORE_CONSTANTS.edit());
		return iconBtn;
	}

	@Override
	public void init() {
		
		currentExpressCheckInConf = new ExpressCheckInConfig();		
		
		vp = new VerticalPanel();
		vp.setId("ExpressCheckInConfigPanel_vpPanel");
		vp.setSpacing(5);
		
		LayoutContainer lc = new LayoutContainer();
		lc.setId("ExpressCheckInConfigPanel_lc");
		lc.setLayout(new ColumnLayout());
		
		Label propLabel = new Label(CoreConstants.CORE_CONSTANTS.property() + CoreConstants.REQURIED_FIELD_LABEL);
		propLabel.setId("ExpressCheckInConfigPanel_propLabel");
		
		propListStore = new ListStore<PropertyIdNameModelData>();
		propCombox = new EasyClearCombobox<PropertyIdNameModelData>();
		propCombox.setId("ExpressCheckInConfigPanel_propCombox");
//		propCombox.setFieldLabel(CoreConstants.CORE_CONSTANTS.property());
		propCombox.setWidth(200);
		propCombox.setDisplayField(CoreConstants.FULLTNAME);
		propCombox.setAllowBlank(false);
		propCombox.setForceSelection(true);
		propCombox.setTriggerAction(TriggerAction.ALL);
		propCombox.setStore(propListStore);
		propCombox.addSelectionChangedListener(new SelectionChangedListener<PropertyIdNameModelData>(){
			@Override
			public void selectionChanged(SelectionChangedEvent<PropertyIdNameModelData> se) {
				myClear();
//				ReservationServiceController.getINSTANCE().getCheckInConf(
//						propCombox.getValue().getEntity().getId(), 
//						new AsyncCallbackListener<CheckInConfiguration>(){
//							@Override
//							public void onLogin(String username) {
//								ReservationServiceController.getINSTANCE().getCheckInConf(
//										SessionContext.getInstance().getPropertyId(),this);
//							}
//							@Override
//							public void onFailure(Throwable caught) {
//								MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
//										CoreConstants.CORE_CONSTANTS.systemError(), null);
//							}
//							@Override
//							public void onSuccess(CheckInConfiguration result) {
//								if(null != result){
//									currentCheckInConf = result;
//									if(null != result.getReqDest()
//										&& result.getReqDest().getDestTypeEnum().equals(NotifDestType.EMAIL)){
//										isFocus = true;
//										printerRadio.setValue(false);
//										emailRadio.setValue(true);
//										emailAddressField.setValue(result.getReqDest().getDestination());
//									}else if(null != result.getReqDest()
//										&& result.getReqDest().getDestTypeEnum().equals(NotifDestType.PRINTER)){
//										isFocus = false;
//										emailRadio.setValue(false);
//										printerRadio.setValue(true);
//										serverNameField.setValue(result.getReqDest().getDestination());
//									}
//									
//									if(null != result.getReqTmpl()){
//										titleField.setValue(result.getReqTmpl().getTitle());
//										textArea.setValue(result.getReqTmpl().getDetail());
//									}
//									
//									timeOutField.setValue(result.getReqTimeout()+"");
//									
//									if(null != result.getToAlertDest()
//											&& result.getToAlertDest().getDestTypeEnum().equals(NotifDestType.EMAIL)){
//											printerRadioAlert.setValue(false);
//											emailRadioAlert.setValue(true);
//											emailAddressField1.setValue(result.getToAlertDest().getDestination());
//									}else if(null != result.getToAlertDest()
//											&& result.getToAlertDest().getDestTypeEnum().equals(NotifDestType.PRINTER)){
//											emailRadioAlert.setValue(false);
//											printerRadioAlert.setValue(true);
//											serverNameField1.setValue(result.getToAlertDest().getDestination());
//									}
//									
//									if(null != result.getToAlertTmpl()){
//										titleField1.setValue(result.getToAlertTmpl().getTitle());
//										textArea1.setValue(result.getToAlertTmpl().getDetail());
//									}
//								}
//							}
//						});
			}
		});
		
		lc.add(propLabel, new ColumnData(70));
		lc.add(propCombox, new ColumnData(160));
		
		vp.add(lc);
		
		FormPanel panel = new FormPanel();
		panel.setId("ExpressCheckInConfigPanel_panel");
		panel.setFrame(true);
		panel.setHeading(CServiceConstants.CSERVICE_CONSTANTS.hotelreservation());
		panel.setPadding(10);
		panel.setSize(730, 530);
		panel.setScrollMode(Scroll.AUTOY);
		panel.setLabelAlign(LabelAlign.LEFT);
		panel.setLabelSeparator("");
		panel.setLabelWidth(120);
		panel.setFieldWidth(400);
		
		LayoutContainer lca = new LayoutContainer();
		
		fieldset1 = new FieldSet();
		fieldset1.setWidth(650);
		fieldset1.setId("ExpressCheckInConfigPanel_fieldset1");
		fieldset1.setHeading(CServiceConstants.CSERVICE_CONSTANTS.checkInRequestSendTo());
		fieldset1.add(lca);
	    panel.add(fieldset1);
		
		HorizontalPanel checkinsendtohp = new HorizontalPanel();
		VerticalPanel emailprinterradiovp = new VerticalPanel();
		emailprinterradiovp.setSpacing(5);
		VerticalPanel emailprintertextvp = new VerticalPanel();
		emailprintertextvp.setSpacing(5);
		
		lca.setId("ExpressCheckInConfigPanel_lca");
	    FormLayout layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		layout.setLabelWidth(120);
		layout.setDefaultWidth(360);
		layout.setLabelSeparator("");
		lca.setLayout(layout);
		lca.setBorders(false);
		
		Label label = new Label("<html><font size=\"3\">" 
				                + CServiceConstants.CSERVICE_CONSTANTS.checkInRequestSendTo()
				                + "</font></html>");
		label.setId("ExpressCheckInConfigPanel_label");
//		lca.add(label);
		
		emailRadio = new Radio();
		emailRadio.setId("ExpressCheckInConfigPanel_emailRadio");
		emailRadio.setBoxLabel(CServiceConstants.CSERVICE_CONSTANTS.emailAddress());
//		emailRadio.setValue(true);
		emailRadio.addListener(Events.Change, new Listener<BaseEvent>(){
			@Override
			public void handleEvent(BaseEvent be) {
				if(emailRadio.getValue()){
//					if(currentExpressCheckInConf.getCheckInRequestSendTo()==1 || isChange){
//						saveButton.setEnabled(true);
//						isChange=true;
//					}
					printerRadio.setValue(false);
					emailAddressField.setEnabled(true);
					emailAddressField.focus();
					serverNameField.setEnabled(false);
					serverNameField.clear();
				}
			}
			
	    });

		printerRadio = new Radio();
		printerRadio.setId("ExpressCheckInConfigPanel_printerRadio");
		printerRadio.setBoxLabel(ShareGWTConstants.SHARE_GWT_CONSTANTS.printer() + " " + CServiceConstants.CSERVICE_CONSTANTS.serverName() + CServiceConstants.FIELD_SEP);
//		printerRadio.setValue(false);
		printerRadio.addListener(Events.Change, new Listener<BaseEvent>(){
			@Override
			public void handleEvent(BaseEvent be) {
				if(printerRadio.getValue()){
//					if(currentExpressCheckInConf.getCheckInRequestSendTo()==0 || isChange){
//						saveButton.setEnabled(true);
//						isChange=true;
//					}
					emailRadio.setValue(false);
					serverNameField.setEnabled(true);
					serverNameField.focus();
					emailAddressField.setEnabled(false);
					emailAddressField.clear();
				}
			}
	    });
	    
	    emailprinterradiovp.add(emailRadio);
	    emailprinterradiovp.add(printerRadio);
	    
	    emailAddressField = new TextField<String>();
	    emailAddressField.setId("ExpressCheckInConfigPanel_emailAddressField");
	    emailAddressField.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.emailAddress() + CServiceConstants.FIELD_SEP);
//	    emailAddressField.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "80px");
	    emailAddressField.setVisible(true);
	    emailAddressField.setEnabled(true);
	    emailAddressField.setWidth(300);
	    emailAddressField.setAllowBlank(false);
	    final String emailReg = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
	    emailAddressField.setValidator(new Validator(){
			@Override
			public String validate(Field<?> field, String value) {
				if (!value.toUpperCase().matches(emailReg)) {
					return ShareGWTConstants.SHARE_GWT_CONSTANTS.emailErro();
				} else if (value.length() > 50) {
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CoreConstants.CORE_CONSTANTS.email(), 50);
				}
				return null;
			}
        });
	    emailAddressField.addListener(Events.KeyUp, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
				// TODO Auto-generated method stub
//				if(!emailAddressField.getValue().trim().equals(currentExpressCheckInConf.getCheckInPrinterEmail()) || isChange){
//					saveButton.setEnabled(true);
//					isChange=true;
//				}
//				else
//					saveButton.setEnabled(false);
			}
		});
	    
	    serverNameField = new TextField<String>();
	    serverNameField.setId("ExpressCheckInConfigPanel_serverNameField");
	    serverNameField.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.serverName() + CServiceConstants.FIELD_SEP);
//	    serverNameField.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "80px");
	    serverNameField.setVisible(true);
	    serverNameField.setEnabled(false);
	    serverNameField.setWidth(300);
	    serverNameField.setAllowBlank(false);
	    serverNameField.setValidator(new Validator(){
			@Override
			public String validate(Field<?> field, String value) {
				if(value != null 
				   && !value.trim().isEmpty()
				   && value.trim().length() > 50){
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CServiceConstants.CSERVICE_CONSTANTS.serverName(), 50);
				}
				return null;
			}
        });
	    serverNameField.addListener(Events.KeyUp, new Listener<BaseEvent>() {

			@Override
			public void handleEvent(BaseEvent be) {
				// TODO Auto-generated method stub
//				if(!serverNameField.getValue().trim().equals(currentExpressCheckInConf.getCheckInPrinterEmail()) || isChange){
//					saveButton.setEnabled(true);
//					isChange=true;
//				}
//				else
//					saveButton.setEnabled(false);
			}
		});
	    
	    emailprintertextvp.add(emailAddressField);
	    emailprintertextvp.add(serverNameField);
	    
	    checkinsendtohp.add(emailprinterradiovp);
	    checkinsendtohp.add(emailprintertextvp);
	    
	    lca.add(checkinsendtohp);
	    
	    LayoutContainer lcRequestsendto = new LayoutContainer();
	    lcRequestsendto.setId("ExpressCheckInConfigPanel_lcc");
	    layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		layout.setLabelWidth(130);
		layout.setDefaultWidth(360);
		layout.setLabelSeparator("");
		lcRequestsendto.setLayout(layout);
		lcRequestsendto.setBorders(false);
		
		fieldsetRequestSubmitted = new FieldSet();
		fieldsetRequestSubmitted.setWidth(650);
		fieldsetRequestSubmitted.setId("ExpressCheckInConfigPanel_fieldsetRequestSubmitted");
		fieldsetRequestSubmitted.setHeading(CServiceConstants.CSERVICE_CONSTANTS.requestsubmitted());
		fieldsetRequestSubmitted.add(lcRequestsendto);
	    panel.add(fieldsetRequestSubmitted);
        
        textareaRequestSubmitted = new TextArea();
        textareaRequestSubmitted.setId("iGuestHousekeepingPanel_textareaRequestSubmitted");
        textareaRequestSubmitted.setValue(CServiceConstants.CSERVICE_CONSTANTS.outofreservationmes());
        textareaRequestSubmitted.setReadOnly(true);
        textareaRequestSubmitted.setHeight(50);
        textareaRequestSubmitted.setWidth(400);
        textareaRequestSubmitted.setFieldLabel(CoreConstants.CORE_CONSTANTS.details() + CServiceConstants.FIELD_SEP);
        
        final HighLightIconButton detailsRequestSubmittedBtn = new HighLightIconButton(
				ShareGWTConstants.CSS_EDIT_SM_ICON,
				new SelectionListener<IconButtonEvent>() {
					@Override
					public void componentSelected(IconButtonEvent ce) {
//						detailsOutofReserDialog.show();
					}
				});
	    
	    HorizontalPanel outofreservationHp = new HorizontalPanel();
	    VerticalPanel outofreservationLabelVp = new VerticalPanel();
	    VerticalPanel outofreservationTextareaVp = new VerticalPanel();
	    VerticalPanel outofreservationIconVp = new VerticalPanel();
	    
	    outofreservationLabelVp.setWidth(120);
	    outofreservationIconVp.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "15px");
	    
	    outofreservationLabelVp.add(new Label(CoreConstants.CORE_CONSTANTS.details() + CServiceConstants.FIELD_SEP));
	    outofreservationTextareaVp.add(textareaRequestSubmitted);
	    outofreservationIconVp.add(detailsRequestSubmittedBtn);
	    
	    outofreservationHp.add(outofreservationLabelVp);
	    outofreservationHp.add(outofreservationTextareaVp);
	    outofreservationHp.add(outofreservationIconVp);
        
        lcRequestsendto.add(outofreservationHp);
        
        //from hotel reservation service
        LayoutContainer lcFromHotel = new LayoutContainer();
        lcFromHotel.setId("iGuestHousekeepingPanel_lcFromHotel");
	    layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		layout.setLabelWidth(130);
		layout.setDefaultWidth(360);
		layout.setLabelSeparator("");
		lcFromHotel.setLayout(layout);
		lcFromHotel.setBorders(false);
        
        fieldsetFromhotelReser = new FieldSet();
        fieldsetFromhotelReser.setWidth(650);
        fieldsetFromhotelReser.setId("iGuestHousekeepingPanel_fieldset4");
        fieldsetFromhotelReser.setHeading(CServiceConstants.CSERVICE_CONSTANTS.fromhotelreservationservice());
        fieldsetFromhotelReser.add(lcFromHotel);
	    panel.add(fieldsetFromhotelReser);
	    
	    fromHotelReserField = new TextField<String>();
	    fromHotelReserField.setId("iGuestHousekeepingPanel_fromHotelReserField");
	    fromHotelReserField.setFieldLabel(CoreConstants.CORE_CONSTANTS.from()+ CServiceConstants.FIELD_SEP);
	    fromHotelReserField.setValue(CServiceConstants.CSERVICE_CONSTANTS.fromhotelreservationservice());
	    fromHotelReserField.setReadOnly(true);
	    fromHotelReserField.setVisible(true);
	    fromHotelReserField.setEnabled(true);
	    fromHotelReserField.setWidth(400);
	    fromHotelReserField.setAllowBlank(false);
//	    econnectrequestfield.setWidth(300);
	    fromHotelReserField.setValidator(new Validator(){
			@Override
			public String validate(Field<?> field, String value) {
				if(value != null 
				   && !value.trim().isEmpty()
				   && value.trim().length() > 50){
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CServiceConstants.CSERVICE_CONSTANTS.fromhotelreservationservice(), 50);
				}
				return null;
			}
        });
	    
//	    fromHousekeepingDialog = new MultiLanguageDialog();
//	    fromHousekeepingDialog.setAllowBlank(false);
//	    fromHousekeepingDialog.addMultiLanguageDialogEventHandler(new MultiLanguageDialogEventHandler() {
//
//			@Override
//			public void onButtonOKClicked(
//					MultiLanguageDialogOKEvent event) {
//				// Get map language-text
//				Map<String, String> values = event.getSource().getLanguageTexts();
//				// Display English in label
//				fromHousekeepingField.setValue(values.get(MultiLanguageDialog.DEFAULT_LANGUAGE));
//				if(!currentFromHKString.equals(values.get(MultiLanguageDialog.DEFAULT_LANGUAGE))||isChange){
//					saveButton.setEnabled(true);
//					isChange=true;
//				}else
//					saveButton.setEnabled(false);
//				//netTextField.setValue(values.get("ja"));
//				//Info.display("result", values.get("en_us") + "-" + values.get("ko"));
//
//			}
//		});
		final HighLightIconButton fromHotelReserBtn = new HighLightIconButton(
				ShareGWTConstants.CSS_EDIT_SM_ICON,
				new SelectionListener<IconButtonEvent>() {
					@Override
					public void componentSelected(IconButtonEvent ce) {
//						fromHousekeepingDialog.show();
					}
				});
	    
	    HorizontalPanel fromhousekeepingHp = new HorizontalPanel();
	    VerticalPanel fromhousekeepingLabelVp = new VerticalPanel();
	    VerticalPanel fromhousekeepingTextfieldVp = new VerticalPanel();
	    VerticalPanel fromhousekeepingIconVp = new VerticalPanel();
	    
	    fromhousekeepingIconVp.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "15px");
	    
	    fromhousekeepingLabelVp.setWidth(120);
	    fromhousekeepingLabelVp.add(new Label(CoreConstants.CORE_CONSTANTS.from()+ CServiceConstants.FIELD_SEP));
	    fromhousekeepingTextfieldVp.add(fromHotelReserField);
	    fromhousekeepingIconVp.add(fromHotelReserBtn);
	    fromhousekeepingHp.add(fromhousekeepingLabelVp);
	    fromhousekeepingHp.add(fromhousekeepingTextfieldVp);
	    fromhousekeepingHp.add(fromhousekeepingIconVp);
	    
	    lcFromHotel.add(fromhousekeepingHp);
	    
	    //subject reservation submitted
	    LayoutContainer lcReserSubmit = new LayoutContainer();
	    lcReserSubmit.setId("iGuestHousekeepingPanel_lce");
	    layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		layout.setLabelWidth(130);
		layout.setDefaultWidth(360);
		layout.setLabelSeparator("");
		lcReserSubmit.setLayout(layout);
		lcReserSubmit.setBorders(false);
		
		fieldsetReserSubmit = new FieldSet();
		fieldsetReserSubmit.setWidth(650);
		fieldsetReserSubmit.setId("iGuestHousekeepingPanel_fieldsetReserSubmit");
		fieldsetReserSubmit.setHeading(CServiceConstants.CSERVICE_CONSTANTS.subjectreservationsubmitted());
		fieldsetReserSubmit.add(lcReserSubmit);
	    panel.add(fieldsetReserSubmit);
	    
	    subjectReserSubmitField = new TextField<String>();
	    subjectReserSubmitField.setId("iGuestHousekeepingPanel_subjectReserSubmitField");
	    subjectReserSubmitField.setFieldLabel(CoreConstants.CORE_CONSTANTS.subject()+ CServiceConstants.FIELD_SEP);
	    subjectReserSubmitField.setValue(CServiceConstants.CSERVICE_CONSTANTS.subjectreservationsubmitted());
	    subjectReserSubmitField.setReadOnly(true);
	    subjectReserSubmitField.setVisible(true);
	    subjectReserSubmitField.setEnabled(true);
	    subjectReserSubmitField.setWidth(400);
	    subjectReserSubmitField.setAllowBlank(false);
//	    econnectrequestfield.setWidth(300);
	    subjectReserSubmitField.setValidator(new Validator(){
			@Override
			public String validate(Field<?> field, String value) {
				if(value != null 
				   && !value.trim().isEmpty()
				   && value.trim().length() > 50){
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CServiceConstants.CSERVICE_CONSTANTS.subjectreservationsubmitted(), 50);
				}
				return null;
			}
        });
	    
//	    subjectHousekeepingDialog = new MultiLanguageDialog();
//	    subjectHousekeepingDialog.setAllowBlank(false);
//	    subjectHousekeepingDialog.addMultiLanguageDialogEventHandler(new MultiLanguageDialogEventHandler() {
//
//			@Override
//			public void onButtonOKClicked(
//					MultiLanguageDialogOKEvent event) {
//				// Get map language-text
//				Map<String, String> values = event.getSource().getLanguageTexts();
//				// Display English in label
//				subjectReserSubmitField.setValue(values.get(MultiLanguageDialog.DEFAULT_LANGUAGE));
//				if(!currentSubjectHKSring.equals(values.get(MultiLanguageDialog.DEFAULT_LANGUAGE))||isChange){
//					saveButton.setEnabled(true);
//					isChange=true;
//				}
//				else
//					saveButton.setEnabled(false);
//				//netTextField.setValue(values.get("ja"));
//				//Info.display("result", values.get("en_us") + "-" + values.get("ko"));
//
//			}
//		});
		final HighLightIconButton subjectHousekeepingBtn = new HighLightIconButton(
				ShareGWTConstants.CSS_EDIT_SM_ICON,
				new SelectionListener<IconButtonEvent>() {
					@Override
					public void componentSelected(IconButtonEvent ce) {
//						subjectHousekeepingDialog.show();
					}
				});
	    
	    HorizontalPanel subjectchangedHp = new HorizontalPanel();
	    VerticalPanel subjectLabelVp = new VerticalPanel();
	    VerticalPanel subjectTextfieldVp = new VerticalPanel();
	    VerticalPanel subjectIconVp = new VerticalPanel();
	    subjectLabelVp.setWidth(120);
	    subjectIconVp.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "15px");
	    subjectLabelVp.add(new Label(CoreConstants.CORE_CONSTANTS.subject()+ CServiceConstants.FIELD_SEP));
	    subjectTextfieldVp.add(subjectReserSubmitField);
	    subjectIconVp.add(subjectHousekeepingBtn);
	    subjectchangedHp.add(subjectLabelVp);
	    subjectchangedHp.add(subjectTextfieldVp);
	    subjectchangedHp.add(subjectIconVp);
	    
	    lcReserSubmit.add(subjectchangedHp);

	    //request submitted message template
	    LayoutContainer lcRequestSubmitMesTem = new LayoutContainer();
		
		fieldsetRequestSubmitMesTem = new FieldSet();
		fieldsetRequestSubmitMesTem.setWidth(650);
		fieldsetRequestSubmitMesTem.setId("ExpressCheckInConfigPanel_fieldsetRequestSubmitMesTem");
		fieldsetRequestSubmitMesTem.setHeading(CServiceConstants.CSERVICE_CONSTANTS.requestsubmitted());
		fieldsetRequestSubmitMesTem.add(lcRequestSubmitMesTem);
	    panel.add(fieldsetRequestSubmitMesTem);	    
	    
	    lcRequestSubmitMesTem.setId("ExpressCheckInConfigPanel_lcCheckInMesTemAlert");
	    layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		layout.setLabelWidth(130);
		layout.setDefaultWidth(360);
		layout.setLabelSeparator("");
		lcRequestSubmitMesTem.setLayout(layout);
		lcRequestSubmitMesTem.setBorders(false);
        
//        titleMessageItemsListStore = new ListStore<MessageItemsExpressGWTEnumModelData>();
//        for(MessageItemsExpressGWTEnum cm : MessageItemsExpressGWTEnum.values()){
//			titleMessageItemsListStore.add(new MessageItemsExpressGWTEnumModelData(cm));
//        }
//        titleMessageItemsCombox = new EasyClearCombobox<MessageItemsExpressGWTEnumModelData>();
//        titleMessageItemsCombox.setId("ExpressCheckInConfigPanel_titleMessageItemsCombox");
//        titleMessageItemsCombox.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.messageField() + CServiceConstants.FIELD_SEP);
////        messageItemsCombox.setWidth(200);
//        titleMessageItemsCombox.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "5px");
//        titleMessageItemsCombox.setDisplayField(CoreConstants.FULLTNAME);
//        titleMessageItemsCombox.setTriggerAction(TriggerAction.ALL);
//        titleMessageItemsCombox.setStore(titleMessageItemsListStore);
//        titleMessageItemsCombox.setForceSelection(true);
//        titleMessageItemsCombox.setEditable(false);
//        titleMessageItemsCombox.setWidth(400);
//        titleMessageItemsCombox.addSelectionChangedListener(new SelectionChangedListener<MessageItemsExpressGWTEnumModelData>(){
//			@Override
//			public void selectionChanged(
//					SelectionChangedEvent<MessageItemsExpressGWTEnumModelData> se) {
//				if(titleMessageItemsCombox.getValue() != null){
//					textAreaexpresscheckin.setValue((textAreaexpresscheckin.getValue() == null ? "" : textAreaexpresscheckin.getValue()) 
//							+ com.fcscs.cservice.common.CServiceConstants.NOTIF_TMPL_DELIM_LEFT 
//							+ titleMessageItemsCombox.getValue().getEnum().getDisplayStr() 
//							+ com.fcscs.cservice.common.CServiceConstants.NOTIF_TMPL_DELIM_RIGHT);
//				}
//			}
//        });
//        titleMessageItemsCombox.addListener(Events.Focus , new Listener<FieldEvent>() {
//			@Override
//			public void handleEvent(FieldEvent be) {
//				if (null != titleMessageItemsCombox.getValue()) {
//					titleMessageItemsCombox.clear();
//					textAreaexpresscheckin.focus();
//				}
//			}
//		});
        
        textAreaexpresscheckin = new TextArea();
        textAreaexpresscheckin.setId("ExpressCheckInConfigPanel_textAreatextAreaexpresscheckin");
        textAreaexpresscheckin.setHeight(130);
        textAreaexpresscheckin.setWidth(400);
        textAreaexpresscheckin.setAllowBlank(false);
        textAreaexpresscheckin.setFieldLabel(CoreConstants.CORE_CONSTANTS.details() + CServiceConstants.FIELD_SEP);
        textAreaexpresscheckin.setValidator(new Validator(){
			@Override
			public String validate(Field<?> field, String value) {
				if(value != null 
				   && !value.trim().isEmpty()
				   && UIUtils.getCharCount(value.trim()) > 500){
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CoreConstants.CORE_CONSTANTS.details(), 500);
				}
				return null;
			}
        });
        
        Label details = new Label(CoreConstants.CORE_CONSTANTS.details() + CServiceConstants.FIELD_SEP);
		HighLightIconButton icon6 = MultiEditBtn();
        
		HorizontalPanel messageforexpresscheckinhp = new HorizontalPanel();
        VerticalPanel messageforexpresscheckinlabelvp = new VerticalPanel();
        VerticalPanel messageforexpresscheckintextfieldvp = new VerticalPanel();
        VerticalPanel messageforexpresscheckiniconvp = new VerticalPanel();
        messageforexpresscheckinhp.setSpacing(5);
        messageforexpresscheckinlabelvp.setSpacing(8);
        messageforexpresscheckinlabelvp.setWidth(110);
        messageforexpresscheckintextfieldvp.setSpacing(5);
        messageforexpresscheckiniconvp.setSpacing(8);
        
//        messageforexpresscheckinlabelvp.add(messagefield2);
        messageforexpresscheckinlabelvp.add(details);
//        messageforexpresscheckintextfieldvp.add(titleMessageItemsCombox);
        messageforexpresscheckintextfieldvp.add(textAreaexpresscheckin);
//        messageforexpresscheckiniconvp.add(icon5);
        messageforexpresscheckiniconvp.add(icon6);
        
        messageforexpresscheckinhp.add(messageforexpresscheckinlabelvp);
        messageforexpresscheckinhp.add(messageforexpresscheckintextfieldvp);
        messageforexpresscheckinhp.add(messageforexpresscheckiniconvp);
        
        lcRequestSubmitMesTem.add(messageforexpresscheckinhp);
        
      //request submitted acknowledgement message template
	    LayoutContainer lcRequestSubmitAckMesTem = new LayoutContainer();
		
		fieldsetRequestSubmitAckMesTem = new FieldSet();
		fieldsetRequestSubmitAckMesTem.setWidth(650);
		fieldsetRequestSubmitAckMesTem.setId("ExpressCheckInConfigPanel_fieldsetRequestSubmitAckMesTem");
		fieldsetRequestSubmitAckMesTem.setHeading(CServiceConstants.CSERVICE_CONSTANTS.requestsubmittedacknowledgement());
		fieldsetRequestSubmitAckMesTem.add(lcRequestSubmitAckMesTem);
	    panel.add(fieldsetRequestSubmitAckMesTem);	    
	    
	    lcRequestSubmitAckMesTem.setId("ExpressCheckInConfigPanel_lcCheckInMesTemAlert");
	    layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		layout.setLabelWidth(130);
		layout.setDefaultWidth(360);
		layout.setLabelSeparator("");
		lcRequestSubmitAckMesTem.setLayout(layout);
		lcRequestSubmitAckMesTem.setBorders(false);
        
//        titleMessageItemsListStore = new ListStore<MessageItemsExpressGWTEnumModelData>();
//        for(MessageItemsExpressGWTEnum cm : MessageItemsExpressGWTEnum.values()){
//			titleMessageItemsListStore.add(new MessageItemsExpressGWTEnumModelData(cm));
//        }
//        titleMessageItemsCombox = new EasyClearCombobox<MessageItemsExpressGWTEnumModelData>();
//        titleMessageItemsCombox.setId("ExpressCheckInConfigPanel_titleMessageItemsCombox");
//        titleMessageItemsCombox.setFieldLabel(CServiceConstants.CSERVICE_CONSTANTS.messageField() + CServiceConstants.FIELD_SEP);
////        messageItemsCombox.setWidth(200);
//        titleMessageItemsCombox.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "5px");
//        titleMessageItemsCombox.setDisplayField(CoreConstants.FULLTNAME);
//        titleMessageItemsCombox.setTriggerAction(TriggerAction.ALL);
//        titleMessageItemsCombox.setStore(titleMessageItemsListStore);
//        titleMessageItemsCombox.setForceSelection(true);
//        titleMessageItemsCombox.setEditable(false);
//        titleMessageItemsCombox.setWidth(400);
//        titleMessageItemsCombox.addSelectionChangedListener(new SelectionChangedListener<MessageItemsExpressGWTEnumModelData>(){
//			@Override
//			public void selectionChanged(
//					SelectionChangedEvent<MessageItemsExpressGWTEnumModelData> se) {
//				if(titleMessageItemsCombox.getValue() != null){
//					textAreaexpresscheckin.setValue((textAreaexpresscheckin.getValue() == null ? "" : textAreaexpresscheckin.getValue()) 
//							+ com.fcscs.cservice.common.CServiceConstants.NOTIF_TMPL_DELIM_LEFT 
//							+ titleMessageItemsCombox.getValue().getEnum().getDisplayStr() 
//							+ com.fcscs.cservice.common.CServiceConstants.NOTIF_TMPL_DELIM_RIGHT);
//				}
//			}
//        });
//        titleMessageItemsCombox.addListener(Events.Focus , new Listener<FieldEvent>() {
//			@Override
//			public void handleEvent(FieldEvent be) {
//				if (null != titleMessageItemsCombox.getValue()) {
//					titleMessageItemsCombox.clear();
//					textAreaexpresscheckin.focus();
//				}
//			}
//		});
        
        textAreaexpresscheckin = new TextArea();
        textAreaexpresscheckin.setId("ExpressCheckInConfigPanel_textAreatextAreaexpresscheckin");
        textAreaexpresscheckin.setHeight(130);
        textAreaexpresscheckin.setWidth(400);
        textAreaexpresscheckin.setAllowBlank(false);
        textAreaexpresscheckin.setFieldLabel(CoreConstants.CORE_CONSTANTS.details() + CServiceConstants.FIELD_SEP);
        textAreaexpresscheckin.setValidator(new Validator(){
			@Override
			public String validate(Field<?> field, String value) {
				if(value != null 
				   && !value.trim().isEmpty()
				   && UIUtils.getCharCount(value.trim()) > 500){
					return ShareGWTConstants.SHARE_GWT_MESSAGES.outOfLength(
							CoreConstants.CORE_CONSTANTS.details(), 500);
				}
				return null;
			}
        });
        
		HorizontalPanel RequestSubmitAckHp = new HorizontalPanel();
        VerticalPanel RequestSubmitAcklabelvp = new VerticalPanel();
        VerticalPanel RequestSubmitAcktextfieldvp = new VerticalPanel();
        VerticalPanel RequestSubmitAckiconvp = new VerticalPanel();
        RequestSubmitAckHp.setSpacing(5);
        RequestSubmitAcklabelvp.setSpacing(8);
        RequestSubmitAcklabelvp.setWidth(110);
        RequestSubmitAcktextfieldvp.setSpacing(5);
        RequestSubmitAckiconvp.setSpacing(8);
        
//        RequestSubmitAcklabelvp.add(new Label(CServiceConstants.CSERVICE_CONSTANTS.messageField() + CServiceConstants.FIELD_SEP));
        RequestSubmitAcklabelvp.add(new Label(CoreConstants.CORE_CONSTANTS.details() + CServiceConstants.FIELD_SEP));
//        RequestSubmitAcktextfieldvp.add(titleMessageItemsCombox);
        RequestSubmitAcktextfieldvp.add(textAreaexpresscheckin);
//        RequestSubmitAckiconvp.add(MultiEditBtn());
        RequestSubmitAckiconvp.add(MultiEditBtn());
        
        RequestSubmitAckHp.add(RequestSubmitAcklabelvp);
        RequestSubmitAckHp.add(RequestSubmitAcktextfieldvp);
        RequestSubmitAckHp.add(RequestSubmitAckiconvp);
        
        lcRequestSubmitAckMesTem.add(RequestSubmitAckHp);
        
	    vp.add(panel);
	    
//	    FormButton saveButton = new FormButton(CoreConstants.CORE_CONSTANTS.save());
	    saveButton = new FormButton(CoreConstants.CORE_CONSTANTS.save());
	    saveButton.setId("ExpressCheckInConfigPanel_saveButton");
		saveButton.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "560px");
		saveButton.setSize(60, 30);
//		saveButton.setEnabled(false);
		saveButton.addSelectionListener(new SelectionListener<ButtonEvent>(){
			@Override
			public void componentSelected(ButtonEvent ce) {
				
					if(timeOutField.isValid() && fromExpressCheckin.isValid() && subjectCheckin.isValid()
							&& subjectCheckinTimeout.isValid() && checkinrequestsubmitted.isValid() && alreadycheckin.isValid()
							&& (emailAddressField.isEnabled() ? emailAddressField.isValid() : true)
							&& (serverNameField.isEnabled() ? serverNameField.isValid() : true)
							&& (emailAddressFieldAlert.isEnabled() ? emailAddressFieldAlert.isValid() : true)
							&& (serverNameFieldAlert.isEnabled() ? serverNameFieldAlert.isValid() : true)){
						
						if(emailRadio.getValue()){
							currentExpressCheckInConf.setCheckInRequestSendTo(0);
							currentExpressCheckInConf.setCheckInPrinterEmail(emailAddressField.getValue());
						}
						else{
							currentExpressCheckInConf.setCheckInRequestSendTo(1);
							currentExpressCheckInConf.setCheckInPrinterEmail(serverNameField.getValue());
						}
						currentExpressCheckInConf.setCheckInMonitorTimeOut(Integer.parseInt(timeOutField.getValue()));
						if(emailRadioAlert.getValue()){
							currentExpressCheckInConf.setCheckInTimeOutAlertSentTo(0);
							currentExpressCheckInConf.setCheckInTimeOutPrinterEmail(emailAddressFieldAlert.getValue());
						}
						else{
							currentExpressCheckInConf.setCheckInTimeOutAlertSentTo(1);
							currentExpressCheckInConf.setCheckInTimeOutPrinterEmail(serverNameFieldAlert.getValue());
						}
						CServiceCommonServiceController.getINSTANCE().saveExpressCheckInConfig(currentExpressCheckInConf,
							new AsyncCallbackListener<ExpressCheckInConfig>(){
	
								@Override
								public void onLogin(String username) {
									// TODO Auto-generated method stub
									CServiceCommonServiceController.getINSTANCE().saveExpressCheckInConfig(currentExpressCheckInConf, this);
								}
	
								@Override
								public void onFailure(Throwable caught) {
									// TODO Auto-generated method stub
									MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
											CoreConstants.CORE_CONSTANTS.systemError(), null);
								}
	
								@Override
								public void onSuccess(ExpressCheckInConfig result) {
									// TODO Auto-generated method stub
									if(null != result){
										CenteredInfo.displayCompleted(CoreConstants.CORE_CONSTANTS.edited());
									}
								}
						});
						
						saveMultiLanguageMap(fromExpresscheckinMap, MultiLanguageConstants.fromExpressCheckIn);
						saveMultiLanguageMap(subjectCheckinRequestMap, MultiLanguageConstants.subjectCheckInRequets);
						saveMultiLanguageMap(subjectCheckinRequestTimeoutMap, MultiLanguageConstants.subjectCheckInRequetsTimeout);
						saveMultiLanguageMap(checkinRequestSubmittedMap, MultiLanguageConstants.checkinRequestSubmitted);
						saveMultiLanguageMap(alreadyCheckinMap, MultiLanguageConstants.alreadyCheckin);
						
//						onShow();
//						saveButton.setEnabled(false);
//						isChange=false;
					}
			}
		});
		
	    vp.add(saveButton);
		
	    CServiceCommonServiceController.getINSTANCE().getLanguageMap(
			new AsyncCallbackListener<Map<String, String>>() {

				@Override
				public void onLogin(String username) {
					CServiceCommonServiceController.getINSTANCE().getLanguageMap(this);
				}

				@Override
				public void onSuccess(Map<String, String> result) {
					final Map<String, String> languages = result;
					fromDialog.setLanguages(languages);
					subjectCheckinRequestDialog.setLanguages(languages);
					subjectCheckinRequestTimeoutDialog.setLanguages(languages);
					subjectCheckinRequestTimeoutDialog.setLanguages(languages);
					checkinRequestSubmittedDialog.setLanguages(languages);
					alreadyCheckinDialog.setLanguages(languages);
				}

				@Override
				public void onFailure(Throwable caught) {
					Info.display("failure", caught.getMessage());
				}
		});
	    
	    add(vp);
		onShow();
	}

	@Override
	public UserAuthority getRequiredAuthority() {
		return CServiceAuthority.cSERVICE_CONFIG;
	}

	@Override
	protected Widget getViewPanel() {
		return vp;
	}

	@Override
	public void onShow() {
		loadProperty();
		myClear();
		//get non language
		CServiceCommonServiceController.getINSTANCE().getExpressCheckInConfig(
			SessionContext.getInstance().getPropertyId(), 
			new AsyncCallbackListener<ExpressCheckInConfig>(){

				@Override
				public void onLogin(String username) {
					// TODO Auto-generated method stub
					CServiceCommonServiceController.getINSTANCE().getExpressCheckInConfig
					(SessionContext.getInstance().getPropertyId(), this);
				}

				@Override
				public void onFailure(Throwable caught) {
					// TODO Auto-generated method stub
					MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
							CoreConstants.CORE_CONSTANTS.systemError(), null);
				}

				@Override
				public void onSuccess(ExpressCheckInConfig result) {
					// TODO Auto-generated method stub
					if(null != result){
						currentExpressCheckInConf = result;
						if(result.getCheckInRequestSendTo()==0){
							emailRadio.setValue(true);
							emailAddressField.setEnabled(true);
							emailAddressField.setValue(result.getCheckInPrinterEmail());
							printerRadio.setValue(false);
							serverNameField.setEnabled(false);
						}
						else{
							printerRadio.setValue(true);
							serverNameField.setEnabled(true);
							serverNameField.setValue(result.getCheckInPrinterEmail());
							emailRadio.setValue(false);
							emailAddressField.setEnabled(false);
						}
						
						timeOutField.setValue(result.getCheckInMonitorTimeOut().toString());
						
						
						if(result.getCheckInTimeOutAlertSentTo()==0){
							emailRadioAlert.setValue(true);
							emailAddressFieldAlert.setEnabled(true);
							emailAddressFieldAlert.setValue(result.getCheckInTimeOutPrinterEmail());
							printerRadioAlert.setValue(false);
							serverNameFieldAlert.setEnabled(false);
						}
						else{
							printerRadioAlert.setValue(true);
							serverNameFieldAlert.setEnabled(true);
							serverNameFieldAlert.setValue(result.getCheckInTimeOutPrinterEmail());
							emailRadioAlert.setValue(false);
							emailAddressFieldAlert.setEnabled(false);
						}
					}
				}
			});
		
			//get from express check in language
				
			CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getOrgId(), MultiLanguageConstants.fromExpressCheckIn,
					new AsyncCallbackListener<List<ConstantsLanguageValue>>(){
	
				@Override
				public void onLogin(String username) {
					CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(),SessionContext.getInstance().getOrgId(), MultiLanguageConstants.fromExpressCheckIn,this);	
					Window.alert("login success!");
				}
	
				@Override
				public void onFailure(Throwable caught) {
					MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
							CoreConstants.CORE_CONSTANTS.systemError(), null);
					Window.alert("get language fail!");
				}
			
				@Override
				public void onSuccess(
					List<ConstantsLanguageValue> result1) {
					fromExpresscheckinMap = convertToMap(result1);
					fromExpressCheckin.setValue(fromExpresscheckinMap.get("en_us"));
					
					//netTextField.setValue(networkAccessNotAvailableConf.get(SessionContext.getInstance().getPropertyLanguage().getDisplayStr()));
					fromDialog.setLanguageTexts(fromExpresscheckinMap);
				}
			});
			
			//get subject check in request language
			
			CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getOrgId(), MultiLanguageConstants.subjectCheckInRequets,
					new AsyncCallbackListener<List<ConstantsLanguageValue>>(){


				@Override
				public void onLogin(String username) {
					CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(),SessionContext.getInstance().getOrgId(),MultiLanguageConstants.subjectCheckInRequets,this);	
					Window.alert("login success!");
				}
	
				@Override
				public void onFailure(Throwable caught) {
					MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
							CoreConstants.CORE_CONSTANTS.systemError(), null);
					Window.alert("get language fail!");
				}
			
	
				@Override
				public void onSuccess(
					List<ConstantsLanguageValue> result1) {
					subjectCheckinRequestMap = convertToMap(result1);
					subjectCheckin.setValue(subjectCheckinRequestMap.get("en_us"));
					
					//netTextField.setValue(networkAccessNotAvailableConf.get(SessionContext.getInstance().getPropertyLanguage().getDisplayStr()));
					subjectCheckinRequestDialog.setLanguageTexts(subjectCheckinRequestMap);
				}
			});
			
			//get subject check in request timeout language
			
			CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getOrgId(), MultiLanguageConstants.subjectCheckInRequetsTimeout,
					new AsyncCallbackListener<List<ConstantsLanguageValue>>(){
	
				@Override
				public void onLogin(String username) {
					CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(),SessionContext.getInstance().getOrgId(),MultiLanguageConstants.subjectCheckInRequetsTimeout,this);	
					Window.alert("login success!");
				}
	
				@Override
				public void onFailure(Throwable caught) {
					MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
							CoreConstants.CORE_CONSTANTS.systemError(), null);
					Window.alert("get language fail!");
				}
			
				@Override
				public void onSuccess(
					List<ConstantsLanguageValue> result1) {
					subjectCheckinRequestTimeoutMap = convertToMap(result1);
					subjectCheckinTimeout.setValue(subjectCheckinRequestTimeoutMap.get("en_us"));
					
					//netTextField.setValue(networkAccessNotAvailableConf.get(SessionContext.getInstance().getPropertyLanguage().getDisplayStr()));
					subjectCheckinRequestTimeoutDialog.setLanguageTexts(subjectCheckinRequestTimeoutMap);
				}
			});
			
			//get check in submitted language
			
			CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getOrgId(), MultiLanguageConstants.checkinRequestSubmitted,
					new AsyncCallbackListener<List<ConstantsLanguageValue>>(){
	
				@Override
				public void onLogin(String username) {
					CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(),SessionContext.getInstance().getOrgId(),MultiLanguageConstants.checkinRequestSubmitted,this);	
					Window.alert("login success!");
				}
	
				@Override
				public void onFailure(Throwable caught) {
					MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
							CoreConstants.CORE_CONSTANTS.systemError(), null);
					Window.alert("get language fail!");
				}
			
				@Override
				public void onSuccess(
					List<ConstantsLanguageValue> result1) {
					checkinRequestSubmittedMap = convertToMap(result1);
					checkinrequestsubmitted.setValue(checkinRequestSubmittedMap.get("en_us"));
					
					//netTextField.setValue(networkAccessNotAvailableConf.get(SessionContext.getInstance().getPropertyLanguage().getDisplayStr()));
					checkinRequestSubmittedDialog.setLanguageTexts(checkinRequestSubmittedMap);
				}
			});
			
			//get already check in language
			
			CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getOrgId(), MultiLanguageConstants.alreadyCheckin,
					new AsyncCallbackListener<List<ConstantsLanguageValue>>(){
	
				@Override
				public void onLogin(String username) {
					CServiceCommonServiceController.getINSTANCE().getListConstantsLanguage(SessionContext.getInstance().getPropertyId(),SessionContext.getInstance().getOrgId(),MultiLanguageConstants.alreadyCheckin,this);	
					Window.alert("login success!");
				}
	
				@Override
				public void onFailure(Throwable caught) {
					MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.system(), ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
							CoreConstants.CORE_CONSTANTS.systemError(), null);
					Window.alert("get language fail!");
				}
			
				@Override
				public void onSuccess(
					List<ConstantsLanguageValue> result1) {
					alreadyCheckinMap = convertToMap(result1);
					alreadycheckin.setValue(alreadyCheckinMap.get("en_us"));
					
					//netTextField.setValue(networkAccessNotAvailableConf.get(SessionContext.getInstance().getPropertyLanguage().getDisplayStr()));
					alreadyCheckinDialog.setLanguageTexts(alreadyCheckinMap);
				}
			});

	}
	
	public Map<String, String> convertToMap( List<ConstantsLanguageValue> listlang ){
		Map<String, String> resultmap = new HashMap<String, String>();
		for(ConstantsLanguageValue lang : listlang){
			resultmap.put(lang.getId().getLanguageId(), lang.getValue());
		}
		return resultmap;
		
	}

	@Override
	public boolean onHide() {
		myClear();
		return true;
	}
	
	private void saveMultiLanguageMap(Map<String, String> abc, String constants){

		for (Entry<String, String> entry : abc.entrySet()) {
			//Window.alert("Key : " + entry.getKey() + " Value : " + entry.getValue());
			if(entry.getValue()!=null){
				final ConstantsLanguageValue multiconstants=new ConstantsLanguageValue();
//				SessionContext.getInstance().getPropertyId()
				//constants=new ConstantsLanguageValueId();
				multiconstants.setId(new ConstantsLanguageValueId(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getOrgId(), constants, entry.getKey()));
				//multiconstants.setId(new ConstantsLanguageValueId(1, 1, "NETWORK_ACCESS_NOT_AVAILABLE", entry.getKey()));
				multiconstants.setValue(entry.getValue());
				multiconstants.setCreated(new Date());
				multiconstants.setUpdated(new Date());
				multiconstants.setCreatedBy(SessionContext.getInstance().getUserId());
				multiconstants.setUpdatedBy(SessionContext.getInstance().getUserId());
				
				CServiceCommonServiceController.getINSTANCE().saveConstantsLanguageValue(multiconstants,
						new AsyncCallbackListener<ConstantsLanguageValue>() {

							@Override
							public void onLogin(String username) {
								CServiceCommonServiceController.getINSTANCE()
										.saveConstantsLanguageValue(multiconstants, this);
							}

							@Override
							public void onFailure(Throwable caught) {
								MessageBox.alert(CoreConstants.CORE_MESSAGES.operation(
										CoreConstants.CORE_CONSTANTS.system(),
										ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
										CoreConstants.CORE_CONSTANTS.systemError(),null);
							}

							@Override
							public void onSuccess(ConstantsLanguageValue result) {
								if (result != null) {
									CenteredInfo.displayCompleted(CoreConstants.CORE_CONSTANTS.edited());
								} else {
									MessageBox.alert(
											CoreConstants.CORE_MESSAGES.operation(
													CoreConstants.CORE_CONSTANTS.system(),
													ShareGWTConstants.SHARE_GWT_CONSTANTS.error()),
											CoreConstants.CORE_CONSTANTS.systemError(),null);
								}
							}
				});
			}//Dong if
		}//Dong For
		//CServiceCommonServiceController.getINSTANCE().saveConstantsLanguageValue(constants, callback);
	}
	
	private void myClear(){
		emailAddressField.clear();
		serverNameField.clear();
//		titleField.clear();
//		textArea.clear();
//		timeOutField.clear();
//		emailAddressFieldAlert.clear();
//		serverNameFieldAlert.clear();
//		titleField1.clear();
//		textArea1.clear();
	}

	@Override
	public void setFocus() {
		if(isFocus){
			emailAddressField.focus();
		}else{
			serverNameField.focus();
		}
	}
	
	private void loadProperty() {
		propGroupIdNames = SessionContext.getInstance().getPropertyGroup();
		propListStore.removeAll();
		if (0 != propGroupIdNames.size()) {
			int propIndex = 0;
			for (IdNameModel<Property> inm : propGroupIdNames) {
				propListStore.add(new PropertyIdNameModelData(inm));
				if (propIndex == 0) {
					if (SessionContext.getInstance().getPropertyId() == inm.getId()) {
						propIndex = propListStore.getCount() - 1;
					}
				}
			}
			propCombox.setValue(propListStore.getAt(propIndex));
		} else {
			IdNameModel<Property> tempINM = new IdNameModel<Property>(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getPropertyName());
			propListStore.add(new PropertyIdNameModelData(tempINM));
			propCombox.setValue(propListStore.getAt(0));
		}
//		propListStore.removeAll();
//		IdNameModel<Property> tempINM = new IdNameModel<Property>(SessionContext.getInstance().getPropertyId(), SessionContext.getInstance().getPropertyName());
//		propListStore.add(new PropertyIdNameModelData(tempINM));
//		propCombox.setValue(propListStore.getAt(0));
//		grid.setCurrentProperty(propListStore.getAt(0));
	}
}

